function displayCommission() {
	var value = $('MarketType').value;
	var commissiondiv = $('CommissionDiv');

	if (value == 2) {
		commissiondiv.style.display = '';
	} else {
		commissiondiv.style.display = 'none';
	}
}

function displayClientDiv(type) {
	var NewClientLink = $('NewClientLink');
	var ExistingClientLink = $('ExistingClientLink');
	var NewClientDiv = $('NewClientDiv');
	var ExistingClientDiv = $('ExistingClientDiv');

	if (type == 1) {
		NewClientLink.style.display = 'none';
		ExistingClientLink.style.display = '';
		NewClientDiv.style.display = '';
		ExistingClientDiv.style.display = 'none';
		MarketClientCheck.value = 1;
	} else {
		NewClientLink.style.display = '';
		ExistingClientLink.style.display = 'none';
		NewClientDiv.style.display = 'none';
		ExistingClientDiv.style.display = '';
		MarketClientCheck.value = 0;
	}
}

function disableEnableDate() {
	var PersonBirthdateNotAvailable = $('PersonBirthdateNotAvailable').checked;
	var PersonBirthdaySelectDay = $('PersonBirthdaySelectDay');
	var PersonBirthdaySelectMonth = $('PersonBirthdaySelectMonth');
	var PersonBirthdaySelectYear = $('PersonBirthdaySelectYear');
	
	if (PersonBirthdateNotAvailable == true) {
		PersonBirthdaySelectDay.setAttribute('disabled', 'disabled');
		PersonBirthdaySelectMonth.setAttribute('disabled', 'disabled');
		PersonBirthdaySelectYear.setAttribute('disabled', 'disabled');
	} else {
		PersonBirthdaySelectDay.removeAttribute('disabled');
		PersonBirthdaySelectMonth.removeAttribute('disabled');
		PersonBirthdaySelectYear.removeAttribute('disabled');
	}
}

function changeCommission(commission) {
	var TransferCommission = $('TransferCommission');
	if (TransferCommission) {
		TransferCommission.value = commission;
	}
}

function displayParentPerson(value) {
	var ParentDiv = $('ParentDiv');
	if (ParentDiv) {
		var personTypesWithParent = [5, 6, 7];
		if (inArray(value,personTypesWithParent)) {
			ParentDiv.style.display = '';
		} else {
			ParentDiv.style.display = 'none';
		}
	}
}

function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}

document.observe('dom:loaded', function() {
	$$('.popup').each(function(el) {
		new Tip(el.down('.popup-source'), el.down('.popup-target'), {
			hook: {tip: 'topMiddle', target: 'bottomMiddle'},
			offset: {x: 0, y: 0},
			hideOn: {element: 'body', event: 'click'},
			images: '/fileadmin/template/images/prototip/styles/default/',
			javascript: '',
			hideAfter: 0.500,
			hideOthers: true,
			border: 0,
			radius: 0,
			delay: 0,
			width: 350,
			closeButton: false
		});

		el.down('.popup-source').observe('prototip:shown', function() {
			document.onclick = Tips.hideAll;
		});
	});
});
